package com.sendpo.zjx.sendpo.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sendpo.zjx.sendpo.R;
import com.sendpo.zjx.sendpo.utils.Tools;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by zjx on 2018
 */

public class StoreCategoryActivity extends AppCompatActivity {


    @BindView(R.id.backbt)
    RelativeLayout backbt;
    @BindView(R.id.head)
    RelativeLayout head;
    @BindView(R.id.listview)
    ListView listview;
    private ListApdater adapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_storecategory);
        Tools.initStatus(this, R.color.black);
        ButterKnife.bind(this);
        initComponent();
    }

    private void initComponent() {
        List<String> as=new ArrayList<>();
        as.add("商品");
        as.add("餐饮");
        as.add("影视");
        as.add("健康");
        as.add("其他");
        listview.setAdapter(adapter=new ListApdater(as));
        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                 if(adapter==null){
                     return;
                 }
                Intent intent = new Intent();
                intent.putExtra("type", adapter.stringList.get(i));
                 setResult(RESULT_OK,intent);
                 finish();
            }
        });
    }

    public class ListApdater
            extends BaseAdapter {
        public List<String> stringList;

        public ListApdater(List<String> stringList) {
            this.stringList = stringList;
        }

        public int getCount() {
            return this.stringList.size();
        }

        public Object getItem(int paramInt) {
            return this.stringList.get(paramInt);
        }

        public long getItemId(int paramInt) {
            return paramInt;
        }

        public View getView(int paramInt, View paramView, ViewGroup paramViewGroup) {
            if (paramView == null) {
                paramView = View.inflate(StoreCategoryActivity.this, R.layout.layout_storecategory, null);
                TextView tv = paramView.findViewById(R.id.name_tv);
                tv.setText("" + stringList.get(paramInt));
                return paramView;
            } else {
                TextView tv = paramView.findViewById(R.id.name_tv);
                tv.setText("" + stringList.get(paramInt));
                return paramView;
            }
        }
    }
    @OnClick(value = {R.id.backbt})
    public void onMyClick(View view){
        switch (view.getId()){
            case R.id.backbt:
                finish();
                break;
        }
    }
}


